#!/bin/bash

#Author Chen
#Date 2016-10-29

eth="wlan0:"      #设备名称
timer=1         #刷新时间 1s

in_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
out_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')

   sleep ${timer}
   in=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
   out=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')
   dif_in=$(((in-in_old)/timer))
  #dif_in=#$((dif_in/1024))
   dif_out=$(((out-out_old)/timer))
  #dif_out=$((dif_out/1024))
  # echo  ${dif_in}       #入网  
  # echo  ${dif_out}      #出网
   awk 'BEGIN{printf "%.2f\n",('$dif_in/1024')}'
   awk 'BEGIN{printf "%.2f\n",('$dif_out/1024')}'
   in_old=${in}
   out_old=${out}
exit 0
